package Api

import (
	"encoding/json"
	"go-study/app/Domain"
	"net/http"
)

func GetVersionHandler(w http.ResponseWriter, r *http.Request) {
	// 设置响应头
	w.Header().Set("Content-Type", "application/json")

	// 只处理 GET 请求
	if r.Method != http.MethodGet {
		http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
		return
	}

	// 从Domain层获取版本信息
	response := Domain.GetVersionInfo()

	// 编码为JSON并发送响应
	if err := json.NewEncoder(w).Encode(response); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
